#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n = 0;
	cin >> n;
	string s;
	getline( cin, s );
	while( n-- )
	{
		string s;
		getline( cin, s );

		int p = s.size() << 2;
		vector<int> seq( p, 0 );
		for( size_t i = 0; i < s.size(); i++ )
		{
			int k = ( i << 2 );
			char c = s[i];
			seq[k] = ( c >> 6 ) & 3;
			seq[k + 1] = ( c >> 4 ) & 3;
			seq[k + 2] = ( c >> 2 ) & 3;
			seq[k + 3] = c & 3;
		}

		int C = 0;
		for( int i = 0; i < p; )
		{
			if( seq[i] == 2 && seq[i + 1] == 0 && seq[i + 2] == 1 )
			{
				C++;
				i += 3;
			}
			else
			{
				i++;
			}
		}

		cout << C << endl;

	}
}
